<?php 
/**
 * QFrameWork
 *
 * Entrance.
 * 
 *
 * @author: quyang
 * @date: 2010-1-17
 * @version: 1.0
 */

define('DELIMITER', '/');
define('NL', "\r\n");
define('TAB', "\t");
define('EXT', ".php");
define('CORE_ROOT', dirname(__FILE__).DELIMITER);
define('SELF', basename(__FILE__));

//PHP settings.
ini_set('DISPLAY_ERRORS', 1);
error_reporting(E_ALL ^ E_NOTICE);

require (CORE_ROOT.'config'.DELIMITER.'global.php');
require (SYS_PATH.'predefine.php');
require (SYS_PATH.'loader.php');

$Router = Loader::load_Lib('router');
$class = $Router->fetch_class();
$method = $Router->fetch_method();
$dir = $Router->fetch_directory();

if (!file_exists(CONTROLLOR_PATH.$dir.$class.EXT)) {
    exit('Unable to load your default controller.  Please make sure the controller specified is valid.');
}

require (CONTROLLOR_PATH.$dir.$class.EXT);


if (!class_exists($class) OR strtolower($method) == 'controller' OR strncmp($method, '_', 1) == 0 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))) {
    exit("No crack please :)");
}

$Instance = new $class;

if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($Instance)))) {
    show_404("Not found Class/Method:{$class}/{$method}");
}

call_user_func_array(array(&$Instance, $method), array_slice($Router->segments, 2));
?>